<template>
	<view class="contianer" :class="'wp-' + platform">
		<cu-custom :bgColor="theme.bgnav" :isBack="true" Barborder="solid-bottom">
			<block slot="content">加入会议</block>
		</cu-custom>
		<view class="mainpageitem">
			<view class="add-box cu-list menu">
				<view class="cu-item" style="padding: 20upx 30upx;">
					<u--input placeholder="请输入会议号" v-model="addForm.roomTag" clearable></u--input>
				</view>
				<view class="cu-item" style="padding: 20upx 30upx;">
					<view class="content">
						<text>启用麦克风</text>
					</view>
					<view class="action" style="max-width: 70%;">
						<u-switch activeColor="#05c160" v-model="addForm.microphone" ></u-switch>
					</view>
				</view>
				<view class="cu-item" style="padding: 20upx 30upx;">
					<view class="content">
						<text>启用摄像头</text>
					</view>
					<view class="action" style="max-width: 70%;">
						<u-switch activeColor="#05c160" v-model="addForm.camera" ></u-switch>
					</view>
				</view>
				
				<!-- <u--input placeholder="请输入会议号" v-model="addForm.roomTag" clearable></u--input>
				<u-switch v-model="addForm.microphone" ></u-switch>
				<u-switch v-model="addForm.camera" ></u-switch> -->
			</view>
			
			<view class="flex flex-direction margin-top padding">
				<button class="cu-btn lg bg-limegreen" @tap="handleAddMetting">加入会议</button>
			</view>
		</view>
	</view>
	
</template>

<script>
	import core from '@/core';
	import store from '@/store';
	import * as API_liveKit from '@/api/livekit'
	import {
		
	} from '@/data/common'
	export default {
		data() {
			return {
				callList: [],
				theme: core.style,
				text: core.langs,
				platform: core.platform,
				addForm:{
					microphone:false,
					camera:false,
					roomTag:'',
				}
			};
		},
		async onLoad() {
			
		},
		computed: {
			
		},
		methods: {
			async handleAddMetting(){
				console.log(this.addForm)
				if(this.addForm.roomTag){
					const roomResp = await this.handleGetRoomInfo(this.addForm.roomTag)
					// return;
					if (this.$nativeRtc.isUIKitEnable()) {
						// 调用原生插件
						this.$nativeRtc.onJoinMeeting({
							"uid":roomResp.data.uid,
							"name":roomResp.data.name,
							"tag":roomResp.data.tag,
							"title":roomResp.data.title,
							"description":roomResp.data.description,
							"muted":roomResp.data.muted,
							"microphoneOn":this.addForm.microphone,
							"cameraOn":this.addForm.camera,
							"fromGroupMode":false,
						})
						return;
					}
					let addForm = JSON.stringify(this.addForm)
					this.naviTo('livekit/metting?type=liveadd&addForm=' + encodeURIComponent(addForm),{},2);
				}else{
					return core.toast('请输入会议号');
				}
			},
			// 创建一个异步函数createMeet，接收一个参数params
			async createMeet(params){
				uni.showLoading({
					title: '正在创建会议...',
					mask: true
				});
				const resp = await API_liveKit.createMeet(params) //  创建房间
				uni.hideLoading();
				if (resp.code == 200 && resp.data) {
					return resp
				} else {
					return core.toast('会议创建失败，请联系管理员')
				}
			},
			// 获取房间详情
			async handleGetRoomInfo(roomTag){
				let params = {
					roomTag: roomTag
				}
				const resp = await API_liveKit.getRoomInfo(params)
				if (resp.code == 200) {
					return resp
				} else {
					this.toast('房间不存在')
					return false
				}
			
			},
		}
	};
</script>

<style lang="scss">
	.add-box{
		width: 90%;
		margin: 40rpx auto;
		border-radius: 20rpx;
		background-color: #fff;
		padding: 20rpx;
	}
</style>